import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.List;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 05-26-22:12
 */
public class VideoUploadInit {
    public static void main(String[] args) throws ClientException {
        //测试从阿里云上面获取视频信息：
//      getPlayUrl();
        getVideoAuth();
    }

    private static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
        String regionId = "cn-shanghai";
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }

    private static void getPlayUrl() {
        try {
            DefaultAcsClient client = initVodClient("LTAI5tLGmiu1XYytf5qGgnTY", "aJEQqXGGSxjOWxsP75YaJ25lZDFgAU");

            GetPlayInfoRequest request = new GetPlayInfoRequest();
            GetPlayInfoResponse response = new GetPlayInfoResponse();

            //设置需要 获取的视频Id值
            request.setVideoId("487c80365c904db7859865f78cabb59b");
            response = client.getAcsResponse(request);

            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            playInfoList.forEach(playInfo -> {
                System.out.println("视频点播的地址：" + playInfo.getPlayURL());
            });

        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    //获取视频的凭证信息：
    private static void getVideoAuth() throws ClientException {
        DefaultAcsClient client = initVodClient("LTAI5tLGmiu1XYytf5qGgnTY", "aJEQqXGGSxjOWxsP75YaJ25lZDFgAU");
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        try {
            response = getVideoPlayAuth(client);
            //播放凭证
            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");

    }

    /**获取播放凭证函数*/
    public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("a40d35fbec854aa4930a953f695717e5");
        return client.getAcsResponse(request);
    }



}
